<template>
  <div>
    <van-picker
      title="性别"
      show-toolbar
      :columns="columns"
      :default-index="value"
      @cancel="$emit('close')"
      @confirm="onConfirm"
    />
  </div>
</template>

<script>
import {setUserProfile} from '@/api/user'

export default {
  props: ['value'],
  data() {
    return {
      columns: ['男', '女']
    }
  },
  methods: {
    async onConfirm(value, index) {
      this.$toast({
        duration: 0,
        message: '加载中'
      })
      try {
        await setUserProfile({
          gender: index
        })
        //  关闭弹框
        this.$emit('close')
        // 修改父组件的名字
        this.$emit('input', index)

        this.$toast('修改性别成功')

      } catch(err) {
        console.log(err)
         this.$toast('修改性别失败')

      }
    }
  }
}
</script>

<style>

</style>
